package com.lee.boot.head.first.demo.socket.config;

import org.springframework.messaging.simp.config.MessageBrokerRegistry;

import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @Auther: Lee
 * @Date: 2018/6/6 14:55
 * @Description:
 */
// 暂时注释掉
//@Configuration
//@EnableWebSocketMessageBroker
// 注解开启使用STOMP协议来传输基于代理(message broker)的消息,这时控制器支持使用@MessageMapping,就像使用@RequestMapping一样
// org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer 在springboot2.0中已过时
// 推荐使用实现下面的We bSocketMessageBrokerConfigurer接口 该接口每个方法都有默认实现
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
        stompEndpointRegistry.addEndpoint("/entry").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 广播式消息配置一个/udp作为代理
        registry.enableSimpleBroker("/udp");
    }

}
